/*
 * 作者: 侯晓宇
 * 时间: 2017-01-24
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {
	require("jquery");

	var c = require('app/utils/CommonUtils');
	var hc = require('app/utils/HttpClientUtils');
	var EventUtils = require('app/utils/EventUtils');
	var RoomInfoUtils = require('app/utils/RoomInfoUtils');
	var UserInfoUtils = require('app/utils/UserInfoUtils');
	var TimePickerUtils = require('app/utils/TimePickerUtils');
	var win = window;

	var action = {};

	action.name_input = function() {
		//参数：
		//	title - 标题栏
		//	limit - 最大字数
		//  value - 初始值
		//  comments - 底部备注
		//	lines - 行数
		//  allowEmpty - 是否允许为空
		//  filterLineBreak - 是否过滤掉换行符
		//  from - 从那个页面启动的TextInput组件，
		//  eventName - 返回值的监听名称
		var param = {
			title: "直播主题",
			limit: 30,
			value: $("#room_name").val(),
			comments: '起一个吸引人的标题吧！',
			lines: 5,
			allowEmpty: false,
			filterLineBreak: true,
			from: api.winName,
			eventName: 'updateRoomName'
		};
		
		api.openWin({
            name: 'TextInputWin',
            url: './TextInputWin.html',
            pageParam:param
        });
	}

	action.livetype_input = function() {
		
		var item = RoomInfoUtils.getRoomLiveTypeByText($("#room_live_type").val());
		var options = RoomInfoUtils.initRoomLiveType();

		//参数：
		//	title - 标题栏
		//	allowMultiple - 是否允许多选，否则为单选
		//  value - 初始值，例如：{val:1;text:"test1"}
		//  options - 备选，例如：[{val:1;text:"test1"}，{val:2;text:"test2"}]
		//  from - 从哪个窗体页面启动的组件，
		//  eventName - 返回值的监听名称
		var param = {
			title: "直播方式",
			allowMultiple: false,
			value: item,
			options: options,
			from: api.winName,
			eventName: 'updateRoomLiveType'
		};
		
		api.openWin({
            name: 'SelectInputWin',
            url: './SelectInputWin.html',
            pageParam:param
        });
	}

	action.starttime_input = function() {
		
		var value = $("#room_starttime").val();
	
		TimePickerUtils.launch(value,function(timestamp){
		
			
			if(c.isNull(timestamp)){
				$("#room_starttime_span").html("立刻开始");
				$("#room_starttime").val("");
			}else{
				$("#room_starttime_span").html(c.timeFormat(timestamp));
				$("#room_starttime").val(timestamp);
			}
		});

	}
	action.des_input = function() {
		//参数：
		//	title - 标题栏
		//	limit - 最大字数
		//  value - 初始值
		//  comments - 底部备注
		//	lines - 行数
		//  allowEmpty - 是否允许为空
		//  filterLineBreak - 是否过滤掉换行符
		//  from - 从那个页面启动的TextInput组件，
		//  eventName - 返回值的监听名称
		var param = {
			title: "详细介绍",
			limit: 500,
			value: $("#room_des").val(),
			comments: '内容分享与观点交流，尽在直播间！',
			lines: 8,
			allowEmpty: true,
			filterLineBreak: false,
			from: api.winName,
			eventName: 'updateRoomDes'
		};
		
		api.openWin({
            name: 'TextInputWin',
            url: './TextInputWin.html',
            pageParam:param
        });
	}
	action.roomtype_input = function() {
		var item = RoomInfoUtils.getRoomPublicTypeByText($("#room_room_type").data("default"));
		var options = RoomInfoUtils.initRoomPublicType();
		for(var i = 0; i< options.length; i++){
			var option_div = $('<option value="'+options[i].val+'">'+options[i].text+'</option>');
			$("#room_room_type").append(option_div);
		}
		$("#room_room_type").val(item.val);
	}
	
	action.roomcatalog_input = function(){
		var item = RoomInfoUtils.getRoomCatalogByText($("#room_catalog").data("default"));
		var options = RoomInfoUtils.initRoomCatalog();
		for(var i = 0; i< options.length; i++){
			var option_div = $('<option style="text-align:right !important;float:right;" value="'+options[i].val+'">'+options[i].text+'</option>');
			$("#room_catalog").append(option_div);
		}
		$("#room_catalog").val(item.val);
	}
	
	action.weixinshare_input = function(){
		$(".wx_share").click(function(){
			$(".wx_share").removeClass("active");
			$(".wx_share").css("color","#757575");
			$(this).addClass("active");
			$(this).css("color","#2f9833");
		});
	}
	
	action.showAdditional = function(publictype){
		if(parseInt(publictype) == 0){
			$("#room_catalog_container").hide();	
			$("#room_share_container").hide();
		}else{
			$("#room_catalog_container").show();
			$("#room_share_container").show();
		}
	}
	action.getRoomVal = function(){
		var msg = {};
		msg.userid = UserInfoUtils.getLoginedUser().userid;
		msg.name = $("#room_name").val();
		msg.live_type = RoomInfoUtils.getRoomLiveTypeByText($("#room_live_type").val()).val;
		if(c.isNullStr($("#room_starttime").val())){
			msg.starttime = (new Date()).getTime();
		}else{
			msg.starttime = parseFloat($("#room_starttime").val());
		}
		msg.des = $("#room_des").val();
		
		msg.room_type = $("#room_room_type").val();
		msg.room_catalog = $("#room_catalog").val();
		
		var item = $("#room_share_container").find(".active");
		
		msg.webchat = item.data("val");
		return msg;		
	}

	return action;
});